package com.hs.srm.admin.modules.pricemanagement.controller;

import java.util.List;
import java.util.Map;
import com.hs.srm.admin.modules.pricemanagement.entity.InquiryItemEntity;
import com.hs.srm.base.common.utils.EntityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import com.hs.srm.admin.modules.pricemanagement.entity.InquiryHeaderEntity;
import com.hs.srm.admin.modules.pricemanagement.service.InquiryHeaderService;
import com.hs.srm.admin.modules.pricemanagement.service.InquiryItemService;
import com.hs.srm.admin.modules.sys.controller.AbstractController;
import com.hs.srm.base.common.annotation.SysLog;
import com.hs.srm.common.utils.PageUtils;
import com.hs.srm.common.utils.R;
import com.hs.srm.common.validator.ValidatorUtils;
import com.hs.srm.common.validator.group.UpdateGroup;

/**
 * 询价单的信息
 * 
 * @author yanfei
 *
 * @date 2019年1月14日
 */
@RestController
@RequestMapping("/inquiryItem")
public class InquiryItemController extends AbstractController {

	private static final long serialVersionUID = -4123823577744890422L;

	// 注入业务层
	@Autowired
	private InquiryHeaderService inquiryHeaderService;
	@Autowired
	private InquiryItemService inquiryItemService;

	/**
	 * 保存询价单的信息
	 */
	@SysLog("保存询价单的信息")
	@RequestMapping("/save")
	@RequiresPermissions("inquiry:save")
	public R save(InquiryHeaderEntity InquiryHeaderEntity) {
		return R.ok();
	}

	/**
	 * 查询询价单信息
	 */
	@RequestMapping("/list")
	public R list(@RequestParam Map<String, Object> params) {
		// 查询用户列表
		PageUtils page = inquiryHeaderService.queryPage(params);
		List<InquiryItemEntity> list= (List<InquiryItemEntity>) page.getList();
		list= EntityUtils.valToTxt(list);
		page.setList(list);
		return R.ok(page);
	}

	/**   
	 * 跳转至询价单编辑页面
	 * @param
	 * @return
	 */
	@RequestMapping("/toEdit/{pkId}")
	public ModelAndView toEdit(@PathVariable("pkId") String pkId) {
		// InquiryHeaderEntity inquiryHeaderEntity = this.inquiryHeaderService.findById(pkId);
		// 把查询出来的对象赋值给供应商实体
		ModelAndView modelAndView = new ModelAndView("modules/vendor/vendor_edit");
		// modelAndView.addObject("inquiryHeaderEntity", inquiryHeaderEntity);
		return modelAndView;
	}

	/**
	 * 更新供应商信息
	 */
	@SysLog("修改询价单信息")
	@RequestMapping("/update")
	@RequiresPermissions("inquiry:update")
	public R update(InquiryHeaderEntity inquiryHeader) {
		ValidatorUtils.validateEntity(inquiryHeader, UpdateGroup.class);
		this.inquiryHeaderService.updateById(inquiryHeader); // 根据id进行更新，没有传值的属性就不会更新
		return R.ok();
	}

}
